//
//  DDPayResultViewController.m
//  DingDongZP
//
//  Created by 杨政涛 on 16/10/19.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

#import "DDPayResultViewController.h"

@interface DDPayResultViewController ()

@end

@implementation DDPayResultViewController

- (void)viewWillAppear:(BOOL)animated
{
    [self.rdv_tabBarController setTabBarHidden:true animated:true];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"充值";
    
    [self configureUI];
}

- (void)configureUI
{
    UILabel *payResultLabel = [[UILabel alloc]init];
    payResultLabel.textColor = COLOR_FONT_DARK_GRAY;
    payResultLabel.font = [UIFont systemFontOfSize:22];
    payResultLabel.text = self.payResult;
    [self.view addSubview:payResultLabel];
    
    UIImageView *showImage = [[UIImageView alloc]init];
    
    if ([self.payResult isEqualToString:@"充值成功"]) {
        
        showImage.image = [UIImage imageNamed:@"paySuccess"];
    }else{
        
        showImage.image = [UIImage imageNamed:@"payFail"];
    }
    
    showImage.layer.masksToBounds = YES;
    [self.view addSubview:showImage];
    
    WEAKSELF
    [payResultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(weakSelf.view).offset(80);
        make.centerX.mas_equalTo(weakSelf.view.centerX).offset(27);
    }];
    
    [showImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(payResultLabel.mas_top).offset(-8);
        make.left.mas_equalTo(payResultLabel.mas_left).offset(-54);
        make.width.equalTo(@(40));
        make.height.equalTo(@(45));
    }];
    
    if ([self.payResult isEqualToString:@"充值成功"]) {
        
        UIButton *paySuccessDone = [UIButton buttonWithType:UIButtonTypeCustom];
        paySuccessDone.backgroundColor = COLOR_BUTTON_MAIN_GREEN;
        paySuccessDone.layer.masksToBounds = YES;
        paySuccessDone.layer.cornerRadius = 5;
        [paySuccessDone setTitle:@"完成" forState:UIControlStateNormal];
        [paySuccessDone addTarget:self action:@selector(paySuccessDoneBackHomePage) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:paySuccessDone];
        
        [paySuccessDone mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(payResultLabel.mas_bottom).offset(80);
            make.left.mas_equalTo(weakSelf.view).offset(30);
            make.right.mas_equalTo(weakSelf.view).offset(-30);
            make.height.equalTo(@(45));
        }];

    }else{
        
        NSArray *buttonTitleArray = @[@"返回首页",@"继续充值"];
        NSArray *backgroundColorArray = @[COLOR_FONT_LIGHT_GREEN,COLOR_BUTTON_MAIN_GREEN];
        CGFloat buttonWidth = (SCREEN_WIDTH-(30*3))/2;
       
        for (int i = 0; i<2; i++) {
            
            
            UIButton *payFailButton = [UIButton buttonWithType:UIButtonTypeCustom];
            payFailButton.tag = 1+i;
            payFailButton.frame = CGRectMake(30+(30+buttonWidth)*i, 180, buttonWidth, 45);
            payFailButton.backgroundColor = backgroundColorArray[i];
            payFailButton.layer.masksToBounds = YES;
            payFailButton.layer.cornerRadius = 5;
            [payFailButton setTitle:buttonTitleArray[i] forState:UIControlStateNormal];
            [payFailButton addTarget:self action:@selector(payFailToBack:) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:payFailButton];
        }
    }
}

/**
 *  充值成功点击完成   充值失败点击返回首页  时候 返回到“我的”  页面
 */
- (void)paySuccessDoneBackHomePage
{
 
    [self.navigationController popToRootViewControllerAnimated:YES];
}

/**
 *  充值失败后点击返回首页/ 继续充值
 */
- (void)payFailToBack:(UIButton *)sender
{
    switch (sender.tag) {
        case 1:
        {
          //返回首页
        [self.navigationController popToRootViewControllerAnimated:YES];
        }
            break;
        case 2:
        {
          // 返回充值页面
        [self.navigationController popViewControllerAnimated:YES];
        }
            break;
        default:
            break;
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    
    [self.rdv_tabBarController setTabBarHidden:false animated:true];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
